# 作者: 赵若云
# 2025年02月20日11时12分06秒
# 3478783573@qq.com


class Person:
    """人类"""

    def __init__(self, name, weight):
        self.name = name
        self.weight = weight

    def __str__(self):
        return "我的名字叫 %s 体重 %.2f 公斤" % (self.name, self.weight)

    def run(self):
        """跑步"""
        print("%s 爱跑步，跑步锻炼身体" % self.name)
        self.weight -= 0.5

    def eat(self):
        """吃东西"""
        print("%s 是吃货，吃完这顿再减肥" % self.name)
        self.weight += 1


# xiaoming = Person("大象", 75)
# xiaoming.run()
# xiaoming.eat()
# xiaoming.eat()
#
# print(xiaoming)

class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return "[%s] 占地 %.2f" % (self.name, self.area)


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []  # 家具列表为空

    def add_item(self, item: HouseItem):  # 冒号：类名是注解的作用，协助写代码的
        print(f'要添加{item}')
        if self.free_area >= item.area:
            self.item_list.append(item.name)
            self.free_area -= item.area
        else:
            print('房间空间不足')

    def __str__(self):
        # Python 能够自动的将一对括号内部的代码连接在一起
        return ("户型：%s\n总面积：%.2f[剩余：%.2f]\n家具：%s"
                % (self.house_type, self.area,
                   self.free_area, self.item_list))


# 1. 创建家具
bed = HouseItem("席梦思", 4)
chest = HouseItem("衣柜", 2)
table = HouseItem("餐桌", 1.5)
# print(bed)
# print(chest)
# print(table)

house = House('三室一厅', 70)
print(house)
house.add_item(bed)
house.add_item(table)
print(house)
